﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
using ZeroBug.EasyFlow.Core;

namespace EasyFlow
{
    public partial class VariableViewModel2 : ObservableObject
    {
        private bool _isLocal;
        private Variable _variable;
        string _name;
        public string Name
        {
            get => _isLocal ? _variable.Name.Split('.')[1] : _variable.Name;
            set
            {
                SetProperty<string>(ref _name, value);
            }
        }
        string _value;
        public string Value
        {
            get => _variable.ToString();
            set
            {
                SetProperty<string>(ref _value, value);
            }
        }
        string _group;
        public string Group
        {
            get => _variable.Group;
            set
            {
                SetProperty<string>(ref _group, value);
            }
        }
        [ObservableProperty]
        bool _isEdit;
        [ObservableProperty]
        ObservableCollection<string> _flowNames;
        public VariableViewModel2(Variable variable, List<string> flowNames, bool isLocal = false)
        {
            _variable = variable;
            _isLocal = isLocal;
            variable.NotifyVariableChanged += onVariableChanged;
            this.FlowNames = new ObservableCollection<string>(flowNames);
        }

        private void onVariableChanged()
        {
            Value = _variable.ToString();
        }
        public Variable GetVariable()
        {
            return _variable;
        }
    }
}
